package Games.PumpGame.Entities 
{
	import flash.events.Event;
	import flash.utils.Timer;
	import Framework.BaseEntity;
	import Games.PumpGame.EventHandler;
	import Games.PumpGame.Gui.TimerBarGui;
	import flash.events.TimerEvent;
	import Games.PumpGame.PumpGame;
	/**
	 * ...
	 * @author Menno
	 */
	public class TimeBar extends BaseEntity
	{
		private var cycleTimer:Timer;
		private var barTimer:Timer;

		private var _cycleSize:int;
		private var _updateTime:int;
		
		public function TimeBar(guiObject:TimerBarGui, cycleTime:int, updateTime:int = 1000) 
		{
			super(guiObject);
			
			_cycleSize = cycleTime;
			(guiComponent as TimerBarGui).updateFilling(cycleSize, 0);
			_updateTime = updateTime;
						
			updateTime = updateTime;
			
			cycleTimer = new Timer(cycleSize);
			cycleTimer.addEventListener(TimerEvent.TIMER, updateCycle);
		
			barTimer = new Timer(updateTime);
			barTimer.addEventListener(TimerEvent.TIMER, updateBar);
			
			cycleTimer.start();	
			barTimer.start();
		}
		
		private function updateBar(e:TimerEvent):void 
		{
			(guiComponent as TimerBarGui).updateFilling(cycleSize, updateTime);
		}
		
		private function updateCycle(e:TimerEvent):void 
		{
			EventHandler.myDispatcher.dispatchEvent(new Event("UPDATE"))
		}
		
		
		//////////////////////////////////////////////////
		//												//
		// 				PROPERTIES						//
		//												//
		//////////////////////////////////////////////////	
		
		public function get cycleSize():int 
		{
			return _cycleSize;
		}
		
		public function set cycleSize(value:int):void 
		{
			_cycleSize = value;
		}
		
		public function get updateTime():int 
		{
			return _updateTime;
		}
		
		public function set updateTime(value:int):void 
		{
			_updateTime = value;
		}
		
	}
	
}